package com.example.demo.controller;

import com.example.demo.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shenb
 * @date 2022-07-08 16:18
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("users")
public class UserController {

    @ApiOperation("查询用户")
    @GetMapping
    public Result<List<User>> list(@ApiParam("姓名模糊匹配") @RequestParam(value = "name", required = false) String name) {
        return Result.success(new ArrayList<>());
    }

    @ApiOperation("创建用户")
    @PutMapping
    public Result<User> create(@RequestBody User user) {
        return Result.success(new User());
    }

    @ApiOperation("修改用户")
    @PostMapping
    public Result<Void> update(@RequestBody User user) {
        return Result.success();
    }

    @ApiOperation("删除用户")
    @DeleteMapping
    public Result<Void> delete() {
        return Result.success();
    }

    @ApiIgnore
    @GetMapping("ignore")
    public Result<Void> ignore() {
        return Result.success();
    }

    @ApiModel("用户")
    static class User {
        @ApiModelProperty("ID")
        public Long id;
        @ApiModelProperty("姓名")
        public String name;
        @ApiModelProperty("年龄")
        public Integer age;
    }
}
